package com.lz.sports.adapter

import androidx.recyclerview.widget.ConcatAdapter
import com.lz.library.adapter.BindingAdapter
import com.lz.sports.bean.PageList

//加载更多列表
class ListMoreAdapter<T>(val adapter: BindingAdapter<T>) {

    private val footerAdapter = FooterAdapter()

    val listAdapter = ConcatAdapter(adapter, footerAdapter)

    fun setPageList(pageList: PageList<T>) {
        val state = pageList.pageState()
        if (state == PageList.EMPTY) {
            adapter.removeAll()
        } else {
            if (pageList.isFirstPage) {
                adapter.setNewData(pageList.list)
            } else {
                adapter.addData(pageList.list)
            }
        }
        footerAdapter.setFooterState(pageList.pageState())
    }
}